package com.lxm.shownews.channel.widget;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import com.lxm.shownews.R;
import com.lxm.shownews.bean.ChannelInfo;
import com.lxm.shownews.channel.adapter.SelectedRecyclerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lxm on 2016/3/1.
 */
public class ChannelPopup extends PopupWindow {

    private View contentView;
    private RecyclerView selectedRecycler;
    private SelectedRecyclerAdapter selectedAdapter;

//    private List<ChannelInfo> channelInfoList;
    private RecyclerView.LayoutManager mLayoutManager;
    private RecyclerView.LayoutManager mGridManager;

    public ChannelPopup(Activity context,List<ChannelInfo> channelInfoList) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        contentView = inflater.inflate(R.layout.channel_popup, null);
        selectedRecycler = (RecyclerView) contentView.findViewById(R.id.selected_recycler);
        mGridManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
        selectedRecycler.setLayoutManager(mGridManager);
        selectedAdapter = new SelectedRecyclerAdapter(channelInfoList);
        selectedRecycler.setAdapter(selectedAdapter);
        this.setContentView(contentView);
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        //        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(Color.parseColor("#BFBFBF"));
        // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ，设置其他控件变化等操作
        this.setBackgroundDrawable(dw);
        this.setFocusable(true);
        this.setAnimationStyle(R.style.AnimationPreview);
    }

    public void showPopup(View parent) {
        if (!this.isShowing()) {
            this.showAsDropDown(parent);
        } else {
            this.dismiss();
        }
    }


}
